package com.example.jsruntimedemo.js;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import com.eclipsesource.v8.V8Object;
import com.example.jsruntimedemo.js.dom.DomElement;
import com.example.jsruntimedemo.js.dom.DomFactory;
import com.example.jsruntimedemo.js.view.JsView;
import com.example.jsruntimedemo.js.view.JsViewFactory;
import com.google.android.material.transition.Hold;

public class RenderManager {
    public RenderManager() {
    }

    private static class Holder {
        private static final RenderManager INSTANCE = new RenderManager();
    }

    public static RenderManager getInstance() {
        return Holder.INSTANCE;
    }

    private Context mContext;
    private ViewGroup mContainerView;

    public void init(Context context, ViewGroup containerView) {
        mContext = context;
        mContainerView = containerView;
    }

    public void render(V8Object rootViewObj) {
        DomElement rootDomElement = DomFactory.create(rootViewObj);
        JsView rootJsView = JsViewFactory.create(rootDomElement);
        if (rootJsView != null) {
            View rootView = rootJsView.createView(mContext);
            mContainerView.addView(rootView);
        }
    }
}
